<?php

namespace App\Logic\point;

use Illuminate\Support\Facades\DB;
use Xrjyz\Curl\Curl;

class Message
{


    public static function index($id){

        $data = DB::table('order as o')
            ->join('user as u','u.username','=','o.user_name')
            ->where('o.id',$id)
            ->select('u.name','u.phone','u.nickname','o.product_name','o.product_capacity','o.product_token','o.pay_type','o.pay_account','o.pay_name','o.buy_num','o.unit_price','o.add_time','o.check_time')
            ->first();

        $new_api_config = [
            'url' => 'https://admin.dianduidian.tech/api_message',
        ];

        $curl = new Curl;

        $curl->post('app_name','wherry')
            ->post('user_name',$data->name?:'default')
            ->post('user_phone',$data->phone)
            ->post('user_nick_name',$data->nickname)
            ->post('product_name',$data->product_name)
            ->post('product_capacity',$data->product_capacity)
            ->post('product_token',$data->product_token)
            ->post('pay_type',$data->pay_type)
            ->post('pay_account',$data->pay_account)
            ->post('pay_name',$data->pay_name)
            ->post('buy_num',$data->buy_num)
            ->post('unit_price',$data->unit_price)
            ->post('buy_time',$data->add_time)
            ->post('check_time',$data->check_time)

            ->url($new_api_config['url']);

        if ( $curl->error() ) {
            return e_msg(300009,$curl->message());
        }
        if($curl->info()['http_code'] == 200){

            $content = $curl->data();
            $info = json_decode($content,true);
            return s_msg('',$info);

        }else{
            return e_msg(300009,'响应异常'.$curl->info()['http_code']);
        }

    }


}





